package io.yunho.spring.cloud.stream.rocketmq.basic;

import org.apache.rocketmq.common.message.MessageConst;
import org.apache.rocketmq.spring.support.RocketMQHeaders;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;
import sun.misc.MessageUtils;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;


/**
 * @author: Jason
 * @date: 2021/4/12 21:03
 * @description:
 */
@Component
public class ScProducer {
    @Resource
    private Source source;
    public void sendMessage(String message){
        Map<String,Object> headers = new HashMap<>();
        headers.put(MessageConst.PROPERTY_TAGS,"testTag");
        MessageHeaders messageHeaders = new MessageHeaders(headers);
        Message<String> msg = MessageBuilder.createMessage(message,messageHeaders);
        this.source.output().send(msg);

//        MessageBuilder<String> builder = MessageBuilder.withPayload(message)
//                .setHeader(RocketMQHeaders.TAGS,"testTag")
//                .setHeader(RocketMQHeaders.KEYS,"myKey")
//                .setHeader("DELAY","1");
//        Message<String> messages = builder.build();
//        this.source.output().send(messages);
    }
}
